package com.springboot.project.common.controller;


import com.springboot.config.annotion.BusinessLog;
import com.springboot.config.tool.PageUtils;
import com.springboot.config.tool.Query;
import com.springboot.config.tool.Tip;
import com.springboot.project.common.entity.Log;
import com.springboot.project.common.service.impl.LogServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author lby
 * @since 2018-06-11
 */
@Controller
@RequestMapping("/log")
public class LogController {

    private static String PREFIX = "system/log/";

    @Autowired
    LogServiceImpl logService;

    /**
     * 跳转到查看日志列表的页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "log";
    }

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        Query query = new Query(params);
        List<Log> logList = logService.list(query);
        int total = logService.count(query);
        PageUtils pageUtil = new PageUtils(logList, total);
        return pageUtil;
    }

    /**
     * 删除 部门表指定数据
     */
    @RequestMapping("/delAll")
    @BusinessLog(value = "清空日志")
    @RequiresPermissions("/log/delAll")
    @ResponseBody
    public Tip delAll() {
        logService.delAll();
        return new Tip();
    }

    /**
     * 详情
     */
    @RequestMapping("/detail/{id}")
    @RequiresPermissions("/log/detail")
    public String userEdit(@PathVariable Integer id, Model model) {

        Log log = logService.selectById(id);
        model.addAttribute("log",log);
        return PREFIX + "log_detail";
    }
}
